package com.lm.paymentadmin.consumer;

import com.lm.paymentadmin.domain.ToEmail;
import com.lm.paymentadmin.service.EmailService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author liuming
 * 异地登录处理
 */
@Component
@RabbitListener(queues = "login_receive_queue")
public class LoginTTLConsumer {

    @Resource
    private EmailService emailService;

    @RabbitHandler
    public void process(Map<String,String> map) {
        ToEmail toEmail = new ToEmail();
        toEmail.setSubject("二狗博客登录提醒！");
        toEmail.setTos(new String[]{map.get("email")});
        toEmail.setContent(map.get("message"));
        emailService.sendEmail(toEmail);
    }
}
